package com.wpzf.ndhc.service.impl;

import com.wpzf.ndhc.utils.TableUtil;
import com.wpzf.ndhc.domain.WpCjDkxxbxjNdDTO;
import com.wpzf.ndhc.domain.WpCjTbxxbxjNdDTO;
import com.wpzf.ndhc.mapper.WpzfNdhcSqthMapper;
import com.wpzf.ndhc.mapper.WpzfNdhcThshMapper;
import com.wpzf.ndhc.mapper.WpzfNdhcXjtbTbBaseMapper;
import com.wpzf.ndhc.service.WpzfNdhcThshService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class WpzfNdhcThshServiceImpl implements WpzfNdhcThshService {

    @Autowired
    private WpzfNdhcThshMapper wpzfNdhcThshMapper;

    @Autowired
    private WpzfNdhcSqthMapper wpzfNdhcSqthMapper;

    @Autowired
    private WpzfNdhcXjtbTbBaseMapper wpzfNdhcXjtbTbBaseMapper;

    @Override
    public List<Map<String, Object>> getPch(Map<String, Object> param) {
        param = TableUtil.TableName(param);
        return wpzfNdhcThshMapper.getPch(param);
    }

    @Override
    public List<Map<String,Object>> getDkList(Map<String, Object> param) {
        param = TableUtil.TableName(param);
        return wpzfNdhcThshMapper.getDkList(param);
    }

    @Override
    public Integer getDkListCount(Map<String, Object> param) {
        param = TableUtil.TableName(param);
        return wpzfNdhcThshMapper.getDkListCount(param);
    }

    @Override
    public WpCjDkxxbxjNdDTO getDkInfoByDkbh(Map<String, Object> param) {
        param = TableUtil.TableName(param);
        return wpzfNdhcThshMapper.getDkInfoByDkbh(param);
    }

    @Override
    public List<WpCjTbxxbxjNdDTO> getTbxxbxjByJcbhList(Map<String, Object> param) {
        param = TableUtil.TableName(param);
        return wpzfNdhcThshMapper.getTbxxbxjByJcbhList(param);
    }

    @Override
    public List<WpCjDkxxbxjNdDTO> queryWpCjDkInfoByJcbh(Map<String, Object> param) {
        param = TableUtil.TableName(param);
        return wpzfNdhcThshMapper.queryWpCjDkInfoByJcbh(param);
    }

    @Override
    public Integer thshSubmit(Map<String, Object> param) {
        param = TableUtil.TableName(param);
        param.put("shsj", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format((new Date()).getTime()));
        List<Map<String,Object>> list = wpzfNdhcThshMapper.queryDkxxbxjNd(param);
        if (list!=null&&list.size()>0) {
            //todo 退回到当前系统
            if ("通过".equals(param.get("shyj")+"")) {
                param.put("dkzt", "9");
                wpzfNdhcXjtbTbBaseMapper.updateDkxxbDkzt(param);
                param.put("userlevel", "国家级地块退回");
                wpzfNdhcXjtbTbBaseMapper.saveDkxxbxjlz(param);
                wpzfNdhcSqthMapper.deleteGJJDK(param);
            }
        } else {
            //todo 退回到国土云
        }
        return wpzfNdhcThshMapper.thshSubmit(param);
    }

    @Override
    public Integer deleteGJJDK(Map<String, Object> param) {
        param = TableUtil.TableName(param);
        return wpzfNdhcSqthMapper.deleteGJJDK(param);
    }

    @Override
    public Integer deleteFjinfo(Map<String, Object> param) {
        param = TableUtil.TableName(param);
        return wpzfNdhcSqthMapper.deleteFjinfo(param);
    }

    @Override
    public Integer updateThDkStatusByDkbh(Map<String, Object> param) {
        param = TableUtil.TableName(param);
        return wpzfNdhcSqthMapper.updateThDkStatusByDkbh(param);
    }

    @Override
    public Integer saveGjjThDk(Map<String, Object> param) {
        param = TableUtil.TableName(param);
        return wpzfNdhcThshMapper.saveGjjThDk(param);
    }


}
